package pyx.crazycards.game.managers;

import pyx.crazycards.game.cards.CardType;
import pyx.crazycards.game.managers.annotation.DataObject;
import pyx.crazycards.game.managers.annotation.Propertie;
import pyx.crazycards.game.managers.persistence.Persistable;

@DataObject(name = "card", base = "crazy.cards.game")
public class Card extends Persistable {
	
	@Propertie(name = "subId")
	private Long subId;
	
	@Propertie(name = "code")
	private Long code;
	
	@Propertie(name = "name")
	private String name;
	
	@Propertie(name = "description")
	private String description;
	
	@Propertie(name = "type")
	private CardType type;
	
	@Propertie(name = "affectEnemy")
	private Boolean affectEnemy = Boolean.FALSE;
	
	@Propertie(name = "action")
	private Action action;
	
	@Propertie(name = "life")
	private Long life = 0L;
	
	@Propertie(name = "cost")
	private ValueProperties cost;
	
	@Propertie(name = "value")
	private ValueProperties value;
	
	@Propertie(name = "defense")
	private ValueProperties defense;
	
	@Propertie(name = "attack")
	private ValueProperties attack;
	
	@Propertie(name = "locked")
	private Boolean locked = Boolean.FALSE;
	
	@Propertie(name = "flipped")
	private Boolean flipped = Boolean.FALSE;
	
	public String getDescription() {
		return description;
	}
	
	public void setDescription(String description) {
		this.description = description;
	}
	
	public CardType getType() {
		return type;
	}
	
	public void setType(CardType type) {
		this.type = type;
	}
	
	public Long getCode() {
		return code;
	}
	
	public void setCode(Long code) {
		this.code = code;
	}
	
	public Action getAction() {
		return action;
	}
	
	public void setAction(Action action) {
		this.action = action;
	}
	
	public ValueProperties getCost() {
		return cost;
	}
	
	public void setCost(ValueProperties cost) {
		this.cost = cost;
	}
	
	public ValueProperties getValue() {
		return value;
	}
	
	public void setValue(ValueProperties value) {
		this.value = value;
	}
	
	public Boolean getLocked() {
		return locked;
	}
	
	public void setLocked(Boolean locked) {
		this.locked = locked;
	}
	
	public Boolean getAffectEnemy() {
		return affectEnemy;
	}
	
	public void setAffectEnemy(Boolean affectEnemy) {
		this.affectEnemy = affectEnemy;
	}
	
	public Long getLife() {
		return life;
	}
	
	public void setLife(Long life) {
		this.life = life;
	}
	
	public Boolean getFlipped() {
		return flipped;
	}
	
	public void setFlipped(Boolean flipped) {
		this.flipped = flipped;
	}
	
	public ValueProperties getDefense() {
		return defense;
	}
	
	public void setDefense(ValueProperties defense) {
		this.defense = defense;
	}
	
	public ValueProperties getAttack() {
		return attack;
	}
	
	public void setAttack(ValueProperties attack) {
		this.attack = attack;
	}
	
	public void addLife(Integer value) {
		this.life += value != null ? value : 0;
	}
	
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public Long getSubId() {
		return subId;
	}
	
	public void setSubId(Long subId) {
		this.subId = subId;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((code == null) ? 0 : code.hashCode());
		return result;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Card other = (Card) obj;
		if (code == null) {
			if (other.code != null)
				return false;
		} else if (!code.equals(other.code))
			return false;
		return true;
	}
	
}
